# output_wrapper.py

class indirect(object):
    def __init__(self, target_machine):
        self.target_machine = target_machine

    def __getattr__(self, name):
        return getattr(self.target_machine, name)

class offset_dest(indirect):
    def __init__(self, dest_machine, offset_fn):
        indirect.__init__(self, dest_machine)
        self.offset_fn = offset_fn

    def with_offset(self, work_to_tool_transform, params):
        return self.offset_fn(work_to_tool_transform, params)

    def rapid(self, work_to_tool_transform, params):
        point = self.with_offset(work_to_tool_transform, params)
        self.target_machine.rapid(point, params)

    def output_point(self, work_to_tool_transform, params):
        point = self.with_offset(work_to_tool_transform, params)
        self.target_machine.output_point(point, params)

class debug_dest(indirect):
    def __init__(self, dest_machine, *debuggers):
        indirect.__init__(self, dest_machine)
        self.debuggers = debuggers

    def start_cut(self, params, line_no=None):
        for debugger in self.debuggers:
            debugger.reset()
        self.target_machine.start_cut(params, line_no)

    def end_cut(self, params):
        for debugger in self.debuggers:
            debugger.report()
        self.target_machine.end_cut(params)

    def output_point(self, point, params):
        self.target_machine.output_point(point, params)
        for debugger in self.debuggers:
            debugger.point(point, params)

